package com.superman.thread;

import com.superman.thread.func.TakeHavingReturnHaving;
import com.superman.thread.func.TakeHavingReturnNothing;
import com.superman.thread.func.TakeNothingReturnHaving;
import com.superman.thread.func.TakeNothingReturnNothing;
import lombok.Data;
import lombok.ToString;

import java.util.Date;

/**
 * 任务提交信息
 * 提交人信息、提交时间、删除时间、删除原因
 * Author: superman
 * Date: 2024/5/22 15:30
 */
@Data
@ToString
public class Submit {

    /**
     * 用户ID
     */
    private String userId;
    /**
     * 别名
     */
    private String alisa;
    /**
     * 任务提交时间
     */
    private Date submitTime;
    /**
     * 任务删除时间
     */
    private Date deleteTime;
    /**
     * 任务删除原因
     */
    private String deleteReason;

    private Submit() {
    }

    public Submit(String userId, String alisa) {
        this.userId = userId;
        this.alisa = alisa;
    }

    /**
     * 创建-无参有返回值的任务
     */
    public <R> Task createTask(String taskId, String taskName, TakeNothingReturnHaving<R> callable) {
        Task task = new Task(taskId, taskName, callable);
        task.setSubmit(this);
        this.submitTime = new Date();
        return task;
    }

    /**
     * 创建-无参无返回值的任务
     */
    public Task createTask(String taskId, String taskName, TakeNothingReturnNothing runnable) {
        Task task = new Task(taskId, taskName, runnable);
        task.setSubmit(this);
        this.submitTime = new Date();
        return task;
    }

    /**
     * 创建-有参有返回值的任务
     */
    public <R> Task createTask(String taskId, String taskName, TakeHavingReturnHaving<R, Object> function, R param) {
        Task task = new Task(taskId, taskName, function, param);
        task.setSubmit(this);
        this.submitTime = new Date();
        return task;
    }

    /**
     * 创建-有参无返回值的任务
     */
    public <R> Task createTask(String taskId, String taskName, TakeHavingReturnNothing<R> consumer, R param) {
        Task task = new Task(taskId, taskName, consumer, param);
        task.setSubmit(this);
        this.submitTime = new Date();
        return task;
    }


}
